<?php

//话题墙控制器
class Wall extends Controller {

	var $viewpath;
	var $is_logined;
	var $prepage = 20;
	
	function Wall()
	{
		parent::Controller();
		$this->viewpath = 'admin/'.__CLASS__;
		$this->load->model('managers_model','mm');
		$this->load->model("wall_model", "wm");
		$this->load->model("forum_model");
		$this->load->model("comment_model", "ctm");
		$this->is_logined = $this->mm->is_logined();
	}
	
	//默认首页
	function index()
	{
		if(!$this->is_logined) {
			redirect($this->config->item('admin_path')."/main/login");
		} 
		$manager = $this->mm->get_account();	
		//获取列表
		if(!$classid = u(4)) $classid = 0;
		$offset = u(5);
		$items = $this->wm->lists($classid, $this->prepage, $offset, "id", "desc", 0);
		//分页数据处理
		$this->load->library('pagination');
		$config['base_url'] = site_url($this->config->item('admin_path')."/wall/index/".$classid);
		$config['total_rows'] = $this->wm->count_lists($classid, 0);
		$config['per_page'] = $this->prepage;
		$config['uri_segment'] = 5;
		$config['num_links'] = 1;
		$config['first_link'] = '首页';
		$config['last_link'] = '末页';
		$config['prev_link'] = '上一页';
		$config['next_link'] = '下一页';
		$this->pagination->initialize($config);
		$pagestring = $this->pagination->create_links();
		
		$viewdata['viewpath'] = $this->viewpath;
		$viewdata['manager'] = $manager;
		$viewdata['items'] = $items;
		$viewdata['pagestring'] = $pagestring;
		$this->load->view($this->viewpath.'/index', $viewdata);
	}
	
	//评论列表
	function comments()
	{
		if(!$this->is_logined) {
			redirect($this->config->item('admin_path')."/main/login");
		} 
		$manager = $this->mm->get_account();	
		//获取列表
		$id = u(4);
		$offset = u(5);
		//获取话题
		$row = $this->forum_model->show($id);
		if(!$row) {
			redirect($this->config->item('admin_path')."/wall/index");
		}
		
		//获取评论列表
		$items = $this->ctm->forum_lists($row["siteid"], $id, $this->prepage, $offset);
		
		//分页数据处理
		$this->load->library('pagination');
		$config['base_url'] = site_url($this->config->item('admin_path')."/wall/comments/".$id);
		$config['total_rows'] = $this->ctm->count_forum_lists($row["siteid"], $id);
		$config['per_page'] = $this->prepage;
		$config['uri_segment'] = 5;
		$config['num_links'] = 1;
		$config['first_link'] = '首页';
		$config['last_link'] = '末页';
		$config['prev_link'] = '上一页';
		$config['next_link'] = '下一页';
		$this->pagination->initialize($config);
		$pagestring = $this->pagination->create_links();
		
		$viewdata['viewpath'] = $this->viewpath;
		$viewdata['manager'] = $manager;
		$viewdata['items'] = $items;
		$viewdata['pagestring'] = $pagestring;
		$viewdata['dataid'] = $id;
		$this->load->view($this->viewpath.'/comments', $viewdata);
	}
	
	//选择推荐
	function recommendselected()
	{
		if(!$delstr = u(4)) redirect($this->config->item('admin_path')."/wall/index");
		$time = time();
		$this->forum_model->recommendselected($delstr, $time);
		admin_show_success("推荐成功", $this->config->item('admin_path')."/wall/index");	
	}
	
	//选择取消推荐
	function unrecommendselected()
	{
		if(!$delstr = u(4)) redirect($this->config->item('admin_path')."/wall/index");
		$this->forum_model->recommendselected($delstr, 0);
		admin_show_success("取消推荐成功", $this->config->item('admin_path')."/wall/index");	
	}
	
	//选择删除
	function delselected()
	{
		if(!$delstr = u(4)) redirect($this->config->item('admin_path')."/wall/index");
		//删除
		$this->forum_model->delselected($delstr);
		admin_show_success("删除成功", $this->config->item('admin_path')."/wall/index");	
	}
	
	//选择删除评论
	function delselectedcomment()
	{
		$dataid = u(4);
		if(!$delstr = u(5)) redirect($this->config->item('admin_path')."/wall/index");
		//删除
		$result = $this->ctm->forum_delete_selected($delstr);
		admin_show_success("删除成功", $this->config->item('admin_path')."/wall/comments/".$dataid);	
	}
	
	//单个删除
	function delete()
	{
		if(!$id = u(4)) redirect($this->config->item('admin_path')."/wall/index");
		//删除
		$this->forum_model->delete($id);
		admin_show_success("删除成功", $this->config->item('admin_path')."/wall/index");	
	}
	
	//单个删除评论
	function deletecomment()
	{
		$dataid = u(4);
		if(!$id = u(5)) redirect($this->config->item('admin_path')."/wall/index");
		//删除
		$this->ctm->forum_delete($id);
		admin_show_success("删除成功", $this->config->item('admin_path')."/wall/comments/".$dataid);	
	}
	
	//查看
	function show()
	{
		$id = u(4);
		//获取信息
		$row = $this->forum_model->show($id);
		$viewdata['viewpath'] = $this->viewpath;
		$viewdata['row'] = $row;
		$this->load->view($this->viewpath.'/show', $viewdata);
	}
	
}

/* End of file */